package com.allwees.bs.module.pms.req.query;

import com.allwees.bs.core.modelbase.req.QueryReq;
import com.allwees.bs.core.modelbase.validate.ValidateItem;
import com.allwees.bs.module.pms.entity.ProductOnoffLog;
import com.allwees.core.common.constant.EStatus;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;

/**
 * Product查询条件
 *
 * @author yangylsky
 * @since 2019-12-18
 *
 */
@Data
@EqualsAndHashCode(callSuper=false)
public class ProductOnoffLogQueryReq extends QueryReq<ProductOnoffLog> {
	private String productUuid;

	private EOnoff onoff;

	private boolean top1 = true;

	@Override
	public String[] getSort() {
		return new String[] {"createdAt:desc"};
	}

	@Override
	public ValidateItem[] getValidateItems() {
		return ArrayUtils.addAll(super.getValidateItems(),
				new ValidateItem(StringUtils.isBlank(productUuid), "商品uuid不能为空"));
	}

	public List<Integer> getActionStatus() {
		if(onoff == null) {
			return ListUtils.union(_getActionStatus(EOnoff.ON), _getActionStatus(EOnoff.OFF));
		}
		return _getActionStatus(onoff);
	}

	private List<Integer> _getActionStatus(EOnoff eOnoff) {
		switch(eOnoff) {
			case ON:
				return Arrays.asList(EStatus.NORMAL.value());
			case OFF:
				return Arrays.asList(
						EStatus.PUTOFF_ONESELF.value(),
						EStatus.PUTOFF_QA_FAILURE.value(),
						EStatus.PUTOFF_OTHERS.value(),
						EStatus.PUTOFF_SELLOUT.value(),
						EStatus.PUTOFF_EDITING.value()
					);
			default:
				throw new IllegalArgumentException();
		}
	}

	public enum EOnoff {
		ON,
		OFF
	}
}
